package com.gzyj.jtt808.v2011.additionalinfo;


import com.gzyj.jtt808.utils.HexBytesUtil;
import com.gzyj.jtt808.v2011.enums.addtionalinfo.JT808_Additional_DrivenRoute;
import io.netty.buffer.ByteBuf;
import lombok.Data;

import java.io.Serializable;

/**
 *路段行驶时间不足_过长报警附加信息
 * @author lhj
 */
@Data
public class JTT808_0x0200_0x13 extends JTT808_AddtionalInfo implements Serializable {
    private int DrivenRouteId;//路段ID
    private short Time;//路段行驶时间
    private JT808_Additional_DrivenRoute DrivenRoute;//结果


    public JTT808_0x0200_0x13() {
        this.setID(0x13);
        this.setLength(7);
    }

    @Override
    public void encode(ByteBuf buf) {
        buf.writeByte(this.getID());
        buf.writeByte(7);
        buf.writeInt(this.DrivenRouteId);
        buf.writeShort(this.Time);
        buf.writeByte(this.DrivenRoute.getCode());
    }

    @Override
    public JTT808_0x0200_0x13 decode(ByteBuf buf) {
        byte[] temp = HexBytesUtil.readByOffset(buf, 1);
        this.setLength(Integer.parseInt(HexBytesUtil.bytesToHex(temp), 16));
        temp= HexBytesUtil.readByOffset(buf,4);
        this.DrivenRouteId=HexBytesUtil.byteArrayToInt(temp);
        temp=HexBytesUtil.readByOffset(buf,2);
        this.Time=Short.parseShort(HexBytesUtil.bytesToHex(temp),16);
        temp=HexBytesUtil.readByOffset(buf,1);
        this.DrivenRoute=JT808_Additional_DrivenRoute.find(Integer.parseInt(HexBytesUtil.bytesToHex(temp),16));

        return this;
    }
}
